
from abc import ABCMeta, abstractmethod


"""
装饰模式优点：
在不改变代码的情况下可以添加额外的功能
"""


class Person(metaclass=ABCMeta):
    """ 人 """

    def __init__(self, name):
        self._name = name

    @abstractmethod
    def wear(self):
        print("穿着：")


class Engineer(Person):
    """ 工程师 """

    def __init__(self, name, skill):
        super().__init__(name)
        self._skill = skill

    def get_skill(self):
        return self._skill

    def wear(self):
        print("我是：" + self.get_skill() + "工程师" + self._name, end=' ')
        super().wear()


class Teacher(Person):

    def __init__(self, name, title):
        super().__init__(name)
        self._title = title

    def get_title(self):
        return self._title

    def wear(self):
        print("我是：" + self._name + self.get_title(), end=' ')
        super().wear()


class ClothesDecorator(Person):
    """ 服装装饰器的基类 """

    def __init__(self, person):
        super().__init__(person)
        self._decorated = person

    def wear(self):
        self._decorated.wear()
        self.decorate()

    @abstractmethod
    def decorate(self):
        pass


class CasualPantDecorator(ClothesDecorator):
    """ 休闲裤装饰器 """

    def __init__(self, person):
        super().__init__(person)

    def decorate(self):
        print("一条卡其色休闲裤")


class BeltDecorator(ClothesDecorator):
    """ 腰带装饰器 """

    def __init__(self, person):
        super().__init__(person)

    def decorate(self):
        print("一条银色针扣头的黑色腰带")


class LeatherShoesDecorator(ClothesDecorator):
    """ 皮鞋装饰器 """

    def __init__(self, person):
        super().__init__(person)

    def decorate(self):
        print("一双深色休闲皮鞋")


class KnittedSweaterDecorator(ClothesDecorator):
    """ 针织毛衣装饰器 """

    def __init__(self, person):
        super().__init__(person)

    def decorate(self):
        print("一件紫红色针织毛衣")


class WhiteShirtDecorator(ClothesDecorator):
    """ 白色衬衫装饰器 """

    def __init__(self, person):
        super().__init__(person)

    def decorate(self):
        print("一件紫红色针织毛衣")


class GlassesDecorator(ClothesDecorator):
    """ 眼睛装饰器 """

    def __init__(self, person):
        super().__init__(person)

    def decorate(self):
        print("一副方形黑框眼睛")


if __name__ == '__main__':
    tony = Engineer("Tony", "python")
    pant = CasualPantDecorator(tony)
    belt = BeltDecorator(pant)
    shoes = LeatherShoesDecorator(belt)
    shirt = WhiteShirtDecorator(shoes)
    sweater = KnittedSweaterDecorator(shirt)
    glasses = GlassesDecorator(sweater)
    glasses.wear()

    print()
    # 下面写法将多个对象的创建过程合在了一起，是一种优雅的写法
    decorateTeacher = GlassesDecorator(WhiteShirtDecorator(LeatherShoesDecorator(Teacher("wells", "教授"))))
    decorateTeacher.wear()

